package pers.qianyu.month_202101.date_20210112;

import java.util.*;

/**
 * 784. 字母大小写全排列
 * https://leetcode-cn.com/problems/letter-case-permutation/
 *
 * @author mizzle rain
 * @date 2021-01-12 16:13
 */
public class LetterCasePermutation {
    public List<String> letterCasePermutation(String s) {
        int len = s.length();
        if (len == 0) return new ArrayList<>();
        List<String> res = new ArrayList<>();
        backTracking(res, s.toCharArray(), 0);
        return new ArrayList<>(res);
    }

    private void backTracking(List<String> res, char[] chars, int cur) {
        if (cur == chars.length) {
            res.add(new String(chars));
            return;
        }
        char ch = chars[cur];
        if (ch >= '0' && ch <= '9') {
            backTracking(res, chars, cur + 1);
            return;
        }
        backTracking(res, chars, cur + 1);
        chars[cur] = (char) (ch ^ 32);
        backTracking(res, chars, cur + 1);
        chars[cur] = ch;
    }
}
